package tyk.statement;

import com.mysql.cj.jdbc.Driver;

import java.sql.*;

/***
 *@title StatementQueryPart
 *@description <TODO description class purpose>
 *@author Tang'ya'kang
 *@VERSION 1.0.0
 *@CREATE 2023/5/3 18:27
 **/
public class StatementQueryPart {
    public static void main(String[] args) throws SQLException {
        //1.注册驱动        DriverManager
        //2。获得连接        Connection
        //3.创建statement     Statement
        //4.发生sql语句，并且获得返回结果    ResultSet
        //5.进行结果集解析
        //6.关闭资源
        DriverManager.registerDriver(new Driver());
        Connection connection=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/javaweb","root","123456");
        Statement statement=connection.createStatement();
        String sql="select * from t_user;";
        ResultSet resultSet=statement.executeQuery(sql);
        while (resultSet.next()){
            int id=resultSet.getInt("id");
            String account=resultSet.getString("account");
            String password=resultSet.getString("password");
            String nickname=resultSet.getString("nickname");
            System.out.println(id+" "+account+" "+password +" "+nickname);
        }
        resultSet.close();
        statement.close();
        connection.close();
    }
}
